/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-06-13
*/
package com.rzico.order.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.basics.entity.Member;
import com.rzico.basics.entity.Product;
import com.rzico.basics.service.MemberService;
import com.rzico.basics.service.ProductService;
import com.rzico.entity.PageResult;
import com.rzico.entity.Pageable;
import com.rzico.order.entity.OrderReview;
import com.rzico.order.model.ReviewMeta;
import com.rzico.order.service.OrderReviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 订单评论控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-06-13
 */
@Api(description = "订单评论接口")
@RestController
@RequestMapping("/review")
public class ReviewController extends BaseController {

    @Autowired
    private OrderReviewService orderReviewService;

    @Autowired
    private ProductService productService;

    /**
     * 分页查询订单评论
     *
     * @return
    */
    @ApiOperation("分页查询订单评论")
    @GetMapping("/list")
    @ApiImplicitParams({@ApiImplicitParam(name = "productId", value = "商品Id", dataType = "String", paramType = "query")
    })
    public CommResult<OrderReview> list(Long productId,Pageable pageable) {
        Map<String, Object> params = new HashMap<String, Object>();
        params = buildSortField(params, pageable);

        if (productId!=null){

            Product product = productService.findById(productId);
            if (product!=null) {
                params.put("goodsId", product.getGoodsId());
            }
        }

        Page<Object> startPage = PageHelper.startPage(pageable.getPageNum(), pageable.getPageSize());
        List<OrderReview> list = orderReviewService.selectList(params);
        PageResult<OrderReview> pageResult = new PageResult<OrderReview>(list, startPage.getTotal(), pageable);
        return CommResult.success(pageResult);
    }

}
